package net.jacktest.jacktest.procedures;

import net.minecraft.potion.EffectInstance;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.Entity;
import net.minecraft.enchantment.EnchantmentHelper;

import net.jacktest.jacktest.potion.JackspowerPotionEffect;
import net.jacktest.jacktest.enchantment.JackpowerEnchantment;
import net.jacktest.jacktest.JacktestMod;

import java.util.Map;

public class SetJacksPower2Procedure {

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			if (!dependencies.containsKey("entity"))
				JacktestMod.LOGGER.warn("Failed to load dependency entity for procedure SetJacksPower2!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		if ((EnchantmentHelper.getEnchantmentLevel(JackpowerEnchantment.enchantment,
				((entity instanceof LivingEntity) ? ((LivingEntity) entity).getHeldItemMainhand() : ItemStack.EMPTY)) != 0)) {
			if (entity instanceof LivingEntity)
				((LivingEntity) entity).addPotionEffect(new EffectInstance(JackspowerPotionEffect.potion, (int) 60, (int) 1));
		} else {
			if (entity instanceof LivingEntity) {
				((LivingEntity) entity).removePotionEffect(JackspowerPotionEffect.potion);
			}
		}
	}
}
